<%-- 
    Document   : exportBase
    Created on : 22 févr. 2012, 16:09:12
    Author     : Fifix
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <%
    if (session.getAttribute("login") == null) {
        request.getRequestDispatcher("/login.jsp").forward(request, response);
    }
    if (session.getAttribute("admin") == null) {
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
    %>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Archiver la base de données</title>
        <c:url value="/iconeWebNotes.gif" var="icone"/>
        <link rel="icon" type="image/gif" href="${icone}"/>
        <c:url value="/css/styleDefaut.css" var="style"/>
        <link rel="stylesheet" media="screen" type="text/css" title="miseEnForme" href="${style}"/>
        <script type="text/javascript">
            window.onload = init;
            
            function init(){
                document.getElementById("confirmer").onclick = exporterBase;
            }

            function exporterBase(){
                var xhr = createXhrObject();
                    xhr.onreadystatechange = function() {
                            if (xhr.readyState == 4) {
                                if(xhr.responseText == "REUSSITE"){
                                    document.getElementById("resultat").innerHTML = "Export terminé!";
                                }
                                else{
                                    document.getElementById("resultat").innerHTML = "L'export a échoué..."
                                }
                            }
                            else{
                                document.getElementById("resultat").innerHTML = "Export en cours...";
                            }
                    };
                    xhr.open("GET", "exportBase?action=exporterBase", true); 
                    xhr.send(null);
                
            }
            
            //Permet de créer l'objet XMLHTTPREQUEST
            function createXhrObject(){
                if (window.XMLHttpRequest)
                    return new XMLHttpRequest();

                if (window.ActiveXObject){
                    var names = [
                        "Msxml2.XMLHTTP.6.0",
                        "Msxml2.XMLHTTP.3.0",
                        "Msxml2.XMLHTTP",
                        "Microsoft.XMLHTTP"
                    ];
                    for(var i in names)
                    {
                        try{return new ActiveXObject(names[i]);}
                        catch(e){}
                    }
                }
                window.alert("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
                return null;
            }
        </script>
    </head>
    <body>
        <p class="navigation">
        <c:url value="/index.jsp" var="menu"/>
        <c:url value="/admin/admin.jsp" var="menuAdmin"/>
        <a href="${menu}"> Menu général </a> &nbsp; &gt; &nbsp; <a href="${menuAdmin}"> Administration </a> &nbsp; &gt; &nbsp; Archiver la base de données <br>
        </p>  
        <h2>Archiver la base de données</h2>
        <button name="confirmer" id="confirmer">Exporter!</button>
        <br />
        <div id="resultat"></div>
    </body>
</html>
